package com.cqeec.netdisc0215.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;

public class UserAuthenticationInterceptor implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		// 验证用户是否登录
		HttpSession session = request.getSession();
		Object obj = session.getAttribute("user");
		if (obj == null) {
			// 未登录，返回到登录页面
			response.sendRedirect(request.getContextPath() + "/login");
			return false;
		} else {
			// 已登录
			return true;
		}
	}

}
